<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script>
// 接收一个Promise数组，在所有promise对象都已经fulfilled或rejected后
// 返回每个promise结果的对象数组. 

// 每个对象有三个属性 
// status => promsie的状态： fulfilled / rejected
// value  =>成功的结果，如果rejected，undfined  
// reason =>失败的原因，如果fulfilled，undefined

const sleep = s => new Promise(resolve => setTimeout(() => { resolve(s) }, s * 1000))

const promises = [
    Promise.resolve(1),
    Promise.reject('error'),
    Promise.resolve(3),
    sleep(5)
]

Promise.allSettled(promises).then(res => {
    // 等结果--> 有了结果，才执行.then的回调
    console.log(res)
})

console.log(1231231)
</script>
</body>
</html>